package org.csu.mypetstore.web.servlets;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.csu.mypetstore.domain.Product;
import org.csu.mypetstore.service.CatalogService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class DisplayFloatServlet extends HttpServlet {
    private String category;
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取鼠标所在图片的动物大类
        category = request.getParameter("category");
        CatalogService service = new CatalogService();

        //获得该类包含的product的相关信息
        List<Product> productList = service.getProductListByCategory(category);
        String resp = " ";
        for(int i=0;i<productList.size();i++) {
            Product product = productList.get(i);
            resp += product.getProductId() + "    "+ product.getName() + "\n";
        }
        response.setContentType("text/xml");
        PrintWriter out = response.getWriter();
        out.write(resp);
    }
}

